#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    string n;
    cin >> n;

    bool rw = true;
    for (char c : n) {
        if (!isdigit(c)) {
            rw = false;
            break;
        }
    }

    if (n.length() != 4 || !rw) {
        cout << 0 << endl;
    } else {
        int num = stoi(n);
        for (int i = 4; i > 0; i--) {
            for (int j = 0; j <= 4 - i; j++) {
                int cr = stoi(n.substr(j, i));
                bool d = true;
                for (int k = 2; k <= sqrt(cr); k++) {
                    if (cr % k == 0) {
                        d = false;
                        break;
                    }
                }
                if (d && cr > 1) {
                    cout << cr << endl;
                    return 0;
                }
            }
        }
        cout << 0 << endl;
    }

    return 0;
}

